    <?php  
      // script name: get_latest_data.php  
      // coder: Sony AK Knowledge Center - www.sony-ak.com  
      // code updated on Feb 26, 2010  
       
      $dbConn = mysql_connect('localhost', 'root', '') or die("Connection to database failed, perhaps the service is down !!");  
      mysql_select_db('test') or die("Database name not available !!");  
       
      $resultSet  = mysql_query("SELECT *, date_format(update_datetime, '%H:%i') AS time_only FROM price_fluctuation ORDER BY update_datetime DESC LIMIT 5", $dbConn); 
	  $resultSet2 = mysql_query("SELECT *, date_format(update_datetime, '%H:%i')+1 AS time2_only FROM price_fluctuation ORDER BY update_datetime DESC LIMIT 5", $dbConn);	  
      $rowCount = mysql_num_rows($resultSet);  
       
      $xmlData = "<graph caption='Price Fluctuation (in USD)' yAxisMinValue='1000' yAxisMaxValue='5000' animation='0' canvasBorderColor='FFFFFF' xAxisName='Time' yAxisName='Price' showNames='1' decimalPrecision='0' formatNumberScale='0'>";  
      $strCategories = "<categories>";
	  $strDataCurr = "<dataset seriesName='Presentation'>";
	  $strDataPrev = "<dataset seriesName='Oppurtinity'>";	
      $index = $rowCount - 1;  
      for ($i=0;$i<$rowCount;$i++) {  
        $updateDatetime = mysql_result($resultSet, $index, "time_only"); 
		$updateDatetime = mysql_result($resultSet2, $index, "time2_only");  	
        $price = mysql_result($resultSet, $index, "price");  
        $xmlData .= "<set name='" . $updateDatetime . "' value='" . $price . "' color='000000' />"; 
		$xmlData .= "<set name='" . $updateDatetime2 . "' value='" . $price . "' color='000000' />";  	
        $index--;  
      }  
      //Close <categories> element
	  $strCategories .= "</categories>";
	  //Close <dataset> elements
	  $strDataCurr .= "</dataset>";
	  $strDataPrev .= "</dataset>"; 
      //$xmlData .= "</graph>";  
      $xmlData .= $strCategories . $strDataCurr . $strDataPrev . "</graph>"; 
      // insert new data, to make fluctuation effect on the chart  
      mysql_query("INSERT INTO price_fluctuation (update_datetime, price) VALUES (now(), " . rand(1000, 5000) . ")", $dbConn);  
       
      echo $xmlData;  
    ?>  